package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAccountTraceMapper;
import com.qf.pojo.DtsAccountTrace;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsAdminBrokerageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class DtsAdminBrokerageServiceImpl implements DtsAdminBrokerageService {

  @Autowired
   DtsAccountTraceMapper traceMapper;

    @Override
    public IPage<DtsAccountTrace> queryPage(Integer page, Integer limit, String sort, String order, String username, String mobile, String[] statusArray) {
        IPage<DtsAccountTrace> ipage = new Page(page, limit);
        QueryWrapper<DtsAccountTrace> qw = new QueryWrapper<>();
        if(!StringUtils.isEmpty(username)) {
            qw.like("username", username);
        }
        if(!StringUtils.isEmpty(mobile)) {
            qw.like("mobile", mobile);
        }
        if(statusArray!=null&&statusArray.length>0){
            qw.in("status",statusArray);
        }
        if(!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            if(order.equalsIgnoreCase("desc")) {
                qw.orderByDesc(sort);
            } else {
                qw.orderByAsc(sort);
            }
        }

        traceMapper.selectPage(ipage, qw);
        return ipage;
    }
}
